package com.spa.infrastructure.mapper;

import com.spa.application.dto.admin.TicketPickRecordExportDTO;
import com.spa.application.dto.member.MemberTicketDTO;
import com.spa.domain.entity.UserTicket;
import com.spa.infrastructure.enums.dict.coupon.CouponComeIntoForceTypeEnum;
import com.spa.infrastructure.enums.dict.coupon.CouponDiscountTypeEnum;
import com.spa.infrastructure.enums.dict.coupon.CouponTypeEnum;
import com.spa.infrastructure.repository.po.UserTicketRefPO;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
@MapperConfig(unmappedTargetPolicy = ReportingPolicy.WARN)
public interface UserTicketMapperStruct {

    UserTicketMapperStruct INSTANCE = Mappers.getMapper(UserTicketMapperStruct.class);


    List<UserTicket> po2Entity4List(List<UserTicketRefPO> poList);

    List<MemberTicketDTO> entity2MemberDto4List(List<UserTicket> entityList);

    UserTicket po2Entity(UserTicketRefPO po);

    List<TicketPickRecordExportDTO> po2RecordDRO4List(List<UserTicket> list);

    @Mapping(source = "discountType", target = "discountType", qualifiedByName = "intDiscountType2Str")
    @Mapping(source = "comeIntoForceType", target = "comeIntoForceType", qualifiedByName = "intForceType2Str")
    @Mapping(source = "type", target = "type", qualifiedByName = "intType2Str")
    TicketPickRecordExportDTO entity2RecordDTO(UserTicket entity);


    @Named("intDiscountType2Str")
    default String intDiscountType2Str(int type) {
        return CouponDiscountTypeEnum.byCode(type).getDesc();
    }

    @Named("intForceType2Str")
    default String intForceType2Str(int type) {
        return CouponComeIntoForceTypeEnum.byCode(type).getDesc();
    }

    @Named("intType2Str")
    default String intType2Str(int type) {
        return CouponTypeEnum.byCode(type).getDesc();
    }

}
